<?
#     Xepec.ru - социальная сеть
#     Copyright (C) 2008-2009  Fedorchenko Alexander
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: sos20@list.ru
#     Date: 30/05/2009
#
#

include "../core.php";
include "lib_picture.php";

////////////////////////////////////////////////////////////
/////////////////Проверка прав на просмот///////////////////
////////////////////////////////////////////////////////////
$auth_id = do_check();                                  ////
if($auth_id == FALSE) header("Location: /");            ////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
/////////////////Правельный вариант/////////////////////////
////////////////////////////////////////////////////////////
$uname_get=$_GET['uname'];                              ////
if (isset($uname_get))                                  ////
{                                                       ////
	if ($uname_get != $auth_id)                     ////
	{                                               ////
		$masha=1;                               ////
	}                                               ////
	$uname_id=$uname_get;                           ////
}                                                       ////
else                                                    ////
{                                                       ////
	$masha=0;                                       ////
	header("Location: index.php?uname=".$auth_id."\n\n");  ////
	$uname_id=$auth_id;                             ////
}                                                       ////
$uname = uname_get($uname_id);                          ////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

# $menu="
#   <ul>
#     <li><a href=\"/username.php?uname=".$id_cook."\">username</a></li>
#     <li><a href=\"/group.php\">Проекты</a></li>
#     <li><a href=\"/litera/index.php?autor=".$id_cook."\">Литература</a></li>
#     <li><a href=\"#\">Кино</a></li>
#     <li><a id=\"now\" href=\"/music/index.php\">Музыка</a></li>
#     <li><a href=\"/picture/index.php?uname=".$id_cook."\">Искуство</a></li>
#     <li><a href=\"#\">Соль</a></li>
#
#   </ul>";
  
$title = "Искуство";

$subnav = "
      <ul>
        <li><a href=\"index.php?uname=".$auth_id."&act=add\">Добавить</a></li>
	<li><a href=\"username.php?uname=".$auth_id."&act=exit\">Выход</a></li>
      </ul>";
    
    #<!--проебаные события-->
# 	if (!show_groups($user_id))
# 	{
# 		$text_1 = " ";
# 	}
# 	else
# 	{
# 		$ss = show_groups($user_id);
# 		for($i=0; $i<count($ss); $i++)
# 		{
# 			$nom=$i+1;
# 			$text_1 = "группа #".$nom.": ".$ss[$i]."<br>";
# 		}
# 	}
    $extras = "
      <h2>Пропущенно</h2>
       <p> <a href=\"#\">Open Web Design</a><br />
       <a rel=\"nofollow\" target=\"_blank\" href=\"http://validator.w3.org/check?uri=referer\">XHTML 1.0 Strict</a><br />
       <a rel=\"nofollow\" target=\"_blank\" href=\"http://jigsaw.w3.org/css-validator/check/referer\">Valid CSS</a> </p>
       <p>Идет тестирование верисии 0.1</p>
     <hr>".$text_1;


$act=$_GET['act'];
if((isset($act)==FALSE) or $act == NULL ) $act='show';
switch ($act)
{
	case "show":
		$count_foto = count_fotos($uname_id);
		
		if(count_fotos($uname_id) == FALSE)
		{
			if ($masha == 1)
			{
				$text=$text."<p>У этого пользователя пока нет ни одной фотографии.</p>";
			}
			else
			{
				$text=$text."<p>У Вас пока нет ни одной фотографии, <a href=\"index.php?uname=".$auth_id."&act=add\">добавить</a></p>";
			}
		}
		else
		{
			if (isset($_COOKIE['xepec_foto'])) add_foto_comment($count_foto, $_POST["comment"]);
			
			//TODO:Доделать фотоальбом
			$text=$text."
			<script type=\"text/javascript\">
			var count_foto = ".$count_foto.";
			function showimg_prev()
			{
			
				var imgg1 = document.getElementById(\"test1\");
				var imgg2 = document.getElementById(\"test2\");
				var imgg3 = document.getElementById(\"test3\");
			
				var sss;
		
		
				sss = document.getElementById('1');
				var c=sss.name;
				var count = parseInt(c);
				count=count-3;
				sss.name = count;
			
				icount = count+1;
				imgg1.src = \"/usr/".$uname_id."/picture/\"+icount + \".png\";
			
				icount = count+2;
				imgg2.src = \"/usr/".$uname_id."/picture/\"+icount + \".png\";
			
				icount = count+3;
				imgg3.src = \"/usr/".$uname_id."/picture/\"+icount + \".png\";
			
			
			}
			function showimg_next()
			{
		
			
				var imgg1 = document.getElementById(\"test1\");
				var imgg2 = document.getElementById(\"test2\");
				var imgg3 = document.getElementById(\"test3\");
			
				var sss;
		
		
				sss = document.getElementById('1');
				var c=sss.name;
				var count = parseInt(c);
				count=count+3;
			
				sss.name = count;
			
				icount = count+1;
				imgg1.src = \"/usr/".$uname_id."/picture/\"+icount + \".png\";
			
				icount = count+2;
				imgg2.src = \"/usr/".$uname_id."/picture/\"+icount + \".png\";
			
				icount = count+3;
				imgg3.src = \"/usr/".$uname_id."/picture\"+icount + \".png\";
			
			
			}



			</script>
			<script src=\"jquery-latest.js\" type=\"text/javascript\"></script>
			<script src=\"thickbox.js\" type=\"text/javascript\"></script>
			<link rel=\"stylesheet\" type=\"text/css\" href=\"thickbox.css\" media=\"screen\" title=\"style (screen)\" />
			<table border=\"1\" width=\"100%\" style=\"table-layout: fixed;\">";
			
			#TODO: Если ты автор то момжешь менять коментакий(опиание) к фотке через AJAX
			//$c=0;
			//while (TRUE == ($c = 1))
			//{
				if ($count_foto > 1)
				$text=$text."
				<tr>
					<td width=\"33%\" height=\"30px\">
						<!--<div id=\"foto\" align=\"center\">
							<div>-->
								<a href=\"/usr/".$uname_id."/picture/2.png\" class=\"thickbox\">
								<img class=\"foto\" id=\"test2\" style=\"max-width=\"10px\";\" src=\"/usr/".$uname_id."/picture/s_2.png\">
								</a>
						<!--	</div>
						</div>-->
					</td>";
				//$c=$c+1;
				if ($count_foto > 0)
				$text=$text."
					<td height=\"30px\>
						<!--div id=\"foto\" align=\"center\">
							<div-->
								<a href=\"/usr/".$uname_id."/picture/1.png\" class=\"thickbox\">
								<img class=\"foto\" id=\"test2\" src=\"/usr/".$uname_id."/picture/s_1.png\">
								</a>
							<!--/div>
						</div-->
					</td>";
				//$c=$c+1;
				if ($count_foto > 2)
				$text=$text."
					<td height=\"30px\>
						<!--div id=\"foto\" align=\"center\">
							<div-->
								<a href=\"/usr/".$uname_id."/picture/3.png\" class=\"thickbox\">
								<img class=\"foto\" id=\"test2\" src=\"/usr/".$uname_id."/picture/s_3.png\">
								</a>
							<!--/div>
						</div-->
					</td>";
					
			$text=$text."	</tr>
			</table>
			";
			//	$c++;
			//}
			if ($count_foto > 3) $text=$text."
					<center>
						<input id=\"1\" name=\"0\" type=\"button\" value=\"&lArr;\" onclick=\"showimg_prev();\"/><input id=\"1\" name=\"0\" type=\"button\" value=\"&rArr;\" onclick=\"showimg_next();\"/></br>
					</center>
			";
		}
	break;
		
	case 'add':
		$text = $text."
		<h2><p><b>Загрузка фотографий</b></p></h2>
		<form action=\"index.php?uname=".$auth_id."&act=add-ok\" method=\"post\" enctype=\"multipart/form-data\" heigth=\"100%\">
		<input type=\"file\" name=\"filename\" heigth=\"100%\"><br> 
		<input type=\"submit\" value=\"Загрузить\"><br>
		</form>
		<p>P.S. размер файла не должет превышать 10 мб</p>";
	break;
	
	case 'add-ok':
	
		/////////////////////Подготовка к обработке////////////////////////////
		if(count_fotos($auth_id) == FALSE) 
		{
			$foto_id = 1;
		}
		else
		{
			$foto_id = count_fotos($auth_id);
		}
		setcookie("xepec_foto", $foto_id, time()+100);
		/////////////////Непосредственно обработка и вывод информации//////////
		if ($_FILES["filename"]["size"] > 1024*1024*10)
		{
			$text = $text."Размер файла превышает 10 мегабайт";
			exit;
		}
		else
		{
			$filename = "$DOC_ROOT/usr/".$auth_id."/picture/".$foto_id.".png";
			$smallimage = "$DOC_ROOT/usr/".$auth_id."/picture/s_".$foto_id.".png";
			
			if(copy($_FILES["filename"]["tmp_name"],$filename))
			{
				resizeimg($filename, $smallimage, 250);
				add_foto($foto_id, "0");
				$text = $text."<h2>Файл успешно загружен </h2>";
				$text = $text."<p>Можете добавть описание";
				$text = $text."<b>Характеристики файла:</b> <br>";
			
				$text = $text.'<form action=index.php?act="show" method=post enctype=\"multipart/form-data\">';
				if ($debug == TRUE) $text = $text.'<table border="1">'; else $text = $text.'<table border="0\">';
				
				$text = $text.'<tr><td><img src="'.$smallimage.'" alt="Вот ваш файл"></td></tr>';
				$text = $text.'<tr><td>Описание:<input type="text" size="20" maxlength="20" name="comment" value=""></td></tr>';
				$text = $text.'</table>';
				$text = $text.'<input type="submit" name="send" value="К альбому"></form></p>';
			}
			else
			{
				$text = $text."Ошибка загрузки файла";
			}
		}
		//////////////////////////Конец обработки////////////////////////////
	break;

}

$content = $text;

include ("../theme.php");
?>